package com.ksp.wke.kspm02;
import static com.ksp.com.KSPCOM_BasConst.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ksp.dom.KSPDOM_ResDta;
import com.ksp.dom.KSPDOM_TabDta;
import com.ksp.dom.KSPDOM_User;

import net.minidev.json.JSONArray;
import net.minidev.json.JSONValue;

/**
 * 用户任务列表查询
 * @author anye
 *
 */
@Controller
public class KSPM02Controller {

	@Autowired
	private KSPM02Mapper kspm02Mapper;

	@RequestMapping("/cmt/KSPM02")
	@ResponseBody
	public KSPDOM_TabDta iniPam(ServletRequest request) {
		String wTtlTch = request.getParameter(TTL_TCH);
		String wSorTyp = request.getParameter(SOR_TYP);
		String wDtaPge = request.getParameter(DTA_PGE).toString();
		String wDtaLmt = request.getParameter(DTA_LMT).toString();
		int wDtaPgeInt = Integer.parseInt(wDtaPge);
		int wDtaLmtInt = Integer.parseInt(wDtaLmt);
		
		//
		Map<String, Object> wPamMap = new HashMap<>();
		wPamMap.put(TTL_TCH, wTtlTch);
		wPamMap.put(SOR_TYP, wSorTyp);
		wPamMap.put(DTA_PGE, (wDtaPgeInt-1) * wDtaLmtInt);
		wPamMap.put(DTA_LMT, wDtaLmtInt);
		KSPDOM_TabDta wCmtPgeDta = new KSPDOM_TabDta();
		try {
			wCmtPgeDta = exeSrv(wPamMap);
		} catch (Exception e) {
			wCmtPgeDta.setCode(1);
			wCmtPgeDta.setMsg(e.getMessage());
		}
		return wCmtPgeDta;
	}

	public KSPDOM_TabDta exeSrv(Map<String, Object> pPamMap) {
		KSPDOM_TabDta wCmtPgeDta = new KSPDOM_TabDta();
		List<Map<String, Object>> wCmtTotalLst = kspm02Mapper.qryCmtTotal(pPamMap);
		String wCmtTolStr = wCmtTotalLst.get(0).get(TOL_CNT).toString();
		List<Map<String, Object>> wQryQuaLst = kspm02Mapper.qryCmtLst(pPamMap);
		wCmtPgeDta.setCode(0);
		wCmtPgeDta.setCount(Integer.parseInt(wCmtTolStr));
		wCmtPgeDta.setData(wQryQuaLst.toArray());

		return wCmtPgeDta;
	}
	
}
